package cn.melon.view.admin.roll;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cn.melon.mod.roll.RollInfo;
import cn.melon.view.admin.library.IUpdateBookTable;
import cn.melon.view.admin.roll.ctr.AddRollCtr;

public class AddRollDlg extends JDialog{
    
    private AddRollCtr listener = new AddRollCtr(this);
    
    private IUpdateBookTable updateBookTable = null;
    
    
    private static final long serialVersionUID = 1L;
    
    private String[] textStr = {"个性签名: ","姓名: ","性别: ","民族: ","学号: ","一卡通号: ","政治面貌: ","婚姻状况: ",
            "学号: ","籍贯: ","出生日期: ","家庭住址: ","校区: ","院系: ","专业: ","当前年级: ","学制: ","手机号码: ","电子邮箱: ", "个性签名: "};
    private JTextField rollUpdateDateChange = new JTextField("",20);
    private JTextField personalMottoChange = new JTextField("",20);
    private JTextField nameChange = new JTextField("",20);
    private JTextField sexChange = new JTextField("",20);
    private JTextField nationChange = new JTextField("",20);
    private JTextField studentNumberChange = new JTextField("",20);
    private JTextField cardNumChange = new JTextField("",20);
    private JTextField politicalStatusChange = new JTextField("",20);
    private JTextField martialStatusChange = new JTextField("",20);
    private JTextField idCardChange = new JTextField("",20);
    private JTextField nativePlaceChange = new JTextField("",20);
    private JTextField dateBirthChange = new JTextField("",20);
    private JTextField addressChange = new JTextField("",20);
    private JTextField curCampusChange = new JTextField("",20);
    private JTextField departmentChange = new JTextField("",20);
    private JTextField majorChange = new JTextField("",20);
    private JTextField curGradeChange = new JTextField("",20);
    private JTextField lengthChange = new JTextField("",20);
    private JTextField phoneChange = new JTextField("",20);
    private JTextField emailChange = new JTextField("",20);
    private JTextField signChange = new JTextField("",20);
    private JTextField[] jTextFields = {personalMottoChange,nameChange,sexChange,nationChange,studentNumberChange,cardNumChange,politicalStatusChange,
            martialStatusChange,idCardChange,nativePlaceChange,dateBirthChange,addressChange,curCampusChange,departmentChange,majorChange,curGradeChange,lengthChange,
            phoneChange,emailChange, signChange};
    
    private JButton saveButton = new JButton("确定");
    private JButton cancelButton = new JButton("取消");
    
    public AddRollDlg() {
        initialize();
    }
    private void initialize(){
        this.setTitle("学籍信息");
        this.setSize(500, 700);
       
        JPanel panel = new JPanel();
        
        GridBagLayout layout = new GridBagLayout();

        panel.setLayout(layout);
        

        for(int i=0;i<textStr.length;i++){
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.anchor = GridBagConstraints.EAST;
            constraints.fill = GridBagConstraints.NONE;
            constraints.gridx = 0;
            constraints.gridy = i;
            constraints.weightx = 100;
            constraints.weighty = 100;
            panel.add(new JLabel(textStr[i]),constraints);
            constraints.anchor = GridBagConstraints.CENTER;
            constraints.gridx = 1;
            panel.add(jTextFields[i],constraints);
            constraints.anchor = GridBagConstraints.EAST;
            constraints.gridx = 2;
            panel.add(Box.createRigidArea(new Dimension(2, 15)));
        }
        
        JPanel tPanel = new JPanel();
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.fill = GridBagConstraints.NONE;
        constraints.gridx = 1;
        constraints.gridy = textStr.length;
        constraints.weightx = 100;
        constraints.weighty = 100;
        tPanel.add(saveButton);     //按钮
        tPanel.add(Box.createRigidArea(new Dimension(10, 15)));
        tPanel.add(cancelButton);
        panel.add(tPanel,constraints);      //按钮
        
        this.add(panel);
        this.setResizable(false);

        saveButton.addActionListener(listener);
        cancelButton.addActionListener(listener);
    }
    
    public RollInfo getRoll(){
        RollInfo rollInfo = new RollInfo();
        
        rollInfo.setName(nameChange.getText());
        rollInfo.setStudentNumber(studentNumberChange.getText());
        rollInfo.setCardNum(cardNumChange.getText());
        rollInfo.setSex(sexChange.getText());
        rollInfo.setNation(nationChange.getText());
        rollInfo.setPoliticalStatus(politicalStatusChange.getText());
        rollInfo.setMaritalStatus(martialStatusChange.getText());
        rollInfo.setIdCard(idCardChange.getText());
        rollInfo.setDateBirth(dateBirthChange.getText());
        rollInfo.setNativePlace(nativePlaceChange.getText());
        rollInfo.setAddress(addressChange.getText());
        rollInfo.setCurCampus(curCampusChange.getText());
        rollInfo.setDepartment(departmentChange.getText());
        rollInfo.setMajor(majorChange.getText());
        rollInfo.setCurGrade(curGradeChange.getText());
        rollInfo.setLength(lengthChange.getText());
        rollInfo.setPhone(phoneChange.getText());
        rollInfo.setCurClass("3");
        rollInfo.setEmail(emailChange.getText());
        rollInfo.setSign(signChange.getText());
        rollInfo.setUpdateDate(rollUpdateDateChange.getText());

        return rollInfo;
    }
}
